import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import { tbstudent, tbteacherlist } from '../../../atoms/db';

const logger = anylogger('pages/api/teacher/s001.api');

export type Idata = Pick<ITbstudent, 'name' | 'student_id' | 'grade' | 'majorname'>;


export type Result = {
	ok: true;
	data: Idata;
} | {
	ok: false;
	message: string;
};

export type Message = {
	id: string;


};



/**
 * pages/api/student/s001.api
 */
const handler = an48<Result>();

handler.post(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);
		const { id } = req.body as Message;
		const data = await tbstudent().first('name', 'student_id', 'grade', 'majorname').where({
			student_id: id
		});

		res.status(200).json({
			ok: true, data

		});
	} catch (error) {
		logger.trace(error);
		res.status(200).json({
			ok: false,
			message: '失败'
		});
	}
});

export const config = {} as PageConfig;

export default handler;
